import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Title: 最长连续不重复子序列
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/3 20:34
 * @description:
 */
public class 最长连续不重复子序列 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 10];
        Map<Integer, Integer> mp = new HashMap<>();


        for(int i = 1; i <= n; ++ i ) {
            a[i] = sc.nextInt();
        }

        int ret = 1;
        for(int i = 1, j = 1; i <= n; ++ i ) { // 走的快的
            int x = a[i];
            mp.merge(x, 1, Integer::sum);
            while(mp.get(x) > 1) {
                mp.merge(a[j], -1, Integer::sum);
                j ++;
               // System.out.println("i = " + i + " j = " + j );
            }
            ret = Math.max(i - j + 1, ret);
           // System.out.println("i = " + i + " j = " + j );
        }
        System.out.println(ret);

        /**
         * 也就是 统计x在map里面的个数的
         */
//        int x = a[1];
//        if(mp.containsKey(x)) {
//            int value = mp.get(x);
//            mp.remove(x);
//            mp.put(x, value + 1);
//        } else {
//            mp.put(x, 1);
//        }

        /**
         * 优化后的代码
         */
        int x = a[0];
        mp.merge(x, 1, Integer::sum);
    }

}
